
<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

  <title>LINK_LIBRARY_OVERRIDE &mdash; CMake 3.27.4 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css" />
    
    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/sphinx_highlight.js"></script>
    
    <link rel="shortcut icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;" href="LINK_LIBRARY_OVERRIDE_LIBRARY.html" />
    <link rel="prev" title="LINK_LIBRARIES_ONLY_TARGETS" href="LINK_LIBRARIES_ONLY_TARGETS.html" />
 

  </head><body>

    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="LINK_LIBRARY_OVERRIDE_LIBRARY.html" title="LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="LINK_LIBRARIES_ONLY_TARGETS.html" title="LINK_LIBRARIES_ONLY_TARGETS"
             accesskey="P">previous</a> |</li>
  <li>
    <img src="../_static/cmake-logo-16.png" alt=""
         style="vertical-align: middle; margin-top: -2px" />
  </li>
  <li>
    <a href="https://cmake.org/">CMake</a> &#187;
  </li>
  <li>
    <a href="../index.html">3.27.4 Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" accesskey="U">cmake-properties(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">LINK_LIBRARY_OVERRIDE</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="link-library-override">
<span id="prop_tgt:LINK_LIBRARY_OVERRIDE"></span><h1>LINK_LIBRARY_OVERRIDE<a class="headerlink" href="#link-library-override" title="Permalink to this heading">¶</a></h1>
<div class="versionadded">
<p><span class="versionmodified added">New in version 3.24.</span></p>
</div>
<p>Override the library features associated with libraries from
<span class="target" id="index-0-genex:LINK_LIBRARY"></span><a class="reference internal" href="../manual/cmake-generator-expressions.7.html#genex:LINK_LIBRARY" title="LINK_LIBRARY"><code class="xref cmake cmake-genex docutils literal notranslate"><span class="pre">LINK_LIBRARY</span></code></a> generator expressions.  This can be used to resolve
incompatible library features that result from specifying different features
for the same library in different <span class="target" id="index-1-genex:LINK_LIBRARY"></span><a class="reference internal" href="../manual/cmake-generator-expressions.7.html#genex:LINK_LIBRARY" title="LINK_LIBRARY"><code class="xref cmake cmake-genex docutils literal notranslate"><span class="pre">LINK_LIBRARY</span></code></a> generator expressions.</p>
<p>This property supports overriding multiple libraries and features. It expects
a <a class="reference internal" href="../manual/cmake-language.7.html#cmake-language-lists"><span class="std std-ref">semicolon-separated list</span></a>, where each list item
has the following form:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>feature[,link-item]*
</pre></div>
</div>
<p>For each comma-separated <code class="docutils literal notranslate"><span class="pre">link-item</span></code>, any existing library feature associated
with it will be ignored for the target this property is set on.  The item
will instead be associated with the specified <code class="docutils literal notranslate"><span class="pre">feature</span></code>.  Each <code class="docutils literal notranslate"><span class="pre">link-item</span></code>
can be anything that would be accepted as part of a <code class="docutils literal notranslate"><span class="pre">library-list</span></code> in a
<span class="target" id="index-2-genex:LINK_LIBRARY"></span><a class="reference internal" href="../manual/cmake-generator-expressions.7.html#genex:LINK_LIBRARY" title="LINK_LIBRARY"><code class="xref cmake cmake-genex docutils literal notranslate"><span class="pre">LINK_LIBRARY</span></code></a> generator expression.</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">add_library(</span><span class="nb">lib1</span><span class="w"> </span><span class="p">...</span><span class="nf">)</span>
<span class="nf">add_library(</span><span class="nb">lib2</span><span class="w"> </span><span class="p">...</span><span class="nf">)</span>
<span class="nf">add_library(</span><span class="nb">lib3</span><span class="w"> </span><span class="p">...</span><span class="nf">)</span>

<span class="nf">target_link_libraries(</span><span class="nb">lib1</span><span class="w"> </span><span class="no">PUBLIC</span><span class="w"> </span><span class="s">&quot;$&lt;LINK_LIBRARY:feature1,external&gt;&quot;</span><span class="nf">)</span>
<span class="nf">target_link_libraries(</span><span class="nb">lib2</span><span class="w"> </span><span class="no">PUBLIC</span><span class="w"> </span><span class="s">&quot;$&lt;LINK_LIBRARY:feature2,lib1&gt;&quot;</span><span class="nf">)</span>
<span class="nf">target_link_libraries(</span><span class="nb">lib3</span><span class="w"> </span><span class="no">PRIVATE</span><span class="w"> </span><span class="nb">lib1</span><span class="w"> </span><span class="nb">lib2</span><span class="nf">)</span>

<span class="c"># lib1 is associated with both feature2 and no feature. Without any override,</span>
<span class="c"># this would result in a fatal error at generation time for lib3.</span>
<span class="c"># Define an override to resolve the incompatible feature associations.</span>
<span class="nf">set_property(</span><span class="no">TARGET</span><span class="w"> </span><span class="nb">lib3</span><span class="w"> </span><span class="no">PROPERTY</span><span class="w"> </span><span class="no">LINK_LIBRARY_OVERRIDE</span><span class="w"> </span><span class="s">&quot;feature2,lib1,external&quot;</span><span class="nf">)</span>

<span class="c"># lib1 and external will now be associated with feature2 instead when linking lib3</span>
</pre></div>
</div>
<p>It is also possible to override any feature with the pre-defined <code class="docutils literal notranslate"><span class="pre">DEFAULT</span></code>
library feature.  This effectively discards any feature for that link item,
for that target only (<code class="docutils literal notranslate"><span class="pre">lib3</span></code> in this example):</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="c"># When linking lib3, discard any library feature for lib1, and use feature2 for external</span>
<span class="nf">set_property(</span><span class="no">TARGET</span><span class="w"> </span><span class="nb">lib3</span><span class="w"> </span><span class="no">PROPERTY</span><span class="w"> </span><span class="no">LINK_LIBRARY_OVERRIDE</span>
<span class="w">  </span><span class="s">&quot;DEFAULT,lib1&quot;</span>
<span class="w">  </span><span class="s">&quot;feature2,external&quot;</span>
<span class="nf">)</span>
</pre></div>
</div>
<p>The above example also demonstrates how to specify different feature overrides
for different link items.  See the <span class="target" id="index-0-prop_tgt:LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;"></span><a class="reference internal" href="LINK_LIBRARY_OVERRIDE_LIBRARY.html#prop_tgt:LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;" title="LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;</span></code></a>
target property for an alternative way of overriding library features for
individual libraries, which may be simpler in some cases.  If both properties
are defined and specify an override for the same link item,
<span class="target" id="index-1-prop_tgt:LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;"></span><a class="reference internal" href="LINK_LIBRARY_OVERRIDE_LIBRARY.html#prop_tgt:LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;" title="LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;</span></code></a> takes precedence over
<code class="docutils literal notranslate"><span class="pre">LINK_LIBRARY_OVERRIDE</span></code>.</p>
<p>Contents of <code class="docutils literal notranslate"><span class="pre">LINK_LIBRARY_OVERRIDE</span></code> may use
<span class="target" id="index-0-manual:cmake-generator-expressions(7)"></span><a class="reference internal" href="../manual/cmake-generator-expressions.7.html#manual:cmake-generator-expressions(7)" title="cmake-generator-expressions(7)"><code class="xref cmake cmake-manual docutils literal notranslate"><span class="pre">generator</span> <span class="pre">expressions</span></code></a>.</p>
<p>For more information about library features, see the
<span class="target" id="index-0-variable:CMAKE_&lt;LANG&gt;_LINK_LIBRARY_USING_&lt;FEATURE&gt;"></span><a class="reference internal" href="../variable/CMAKE_LANG_LINK_LIBRARY_USING_FEATURE.html#variable:CMAKE_&lt;LANG&gt;_LINK_LIBRARY_USING_&lt;FEATURE&gt;" title="CMAKE_&lt;LANG&gt;_LINK_LIBRARY_USING_&lt;FEATURE&gt;"><code class="xref cmake cmake-variable docutils literal notranslate"><span class="pre">CMAKE_&lt;LANG&gt;_LINK_LIBRARY_USING_&lt;FEATURE&gt;</span></code></a> and
<span class="target" id="index-0-variable:CMAKE_LINK_LIBRARY_USING_&lt;FEATURE&gt;"></span><a class="reference internal" href="../variable/CMAKE_LINK_LIBRARY_USING_FEATURE.html#variable:CMAKE_LINK_LIBRARY_USING_&lt;FEATURE&gt;" title="CMAKE_LINK_LIBRARY_USING_&lt;FEATURE&gt;"><code class="xref cmake cmake-variable docutils literal notranslate"><span class="pre">CMAKE_LINK_LIBRARY_USING_&lt;FEATURE&gt;</span></code></a> variables.</p>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="LINK_LIBRARIES_ONLY_TARGETS.html"
                          title="previous chapter">LINK_LIBRARIES_ONLY_TARGETS</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="LINK_LIBRARY_OVERRIDE_LIBRARY.html"
                          title="next chapter">LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/prop_tgt/LINK_LIBRARY_OVERRIDE.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="LINK_LIBRARY_OVERRIDE_LIBRARY.html" title="LINK_LIBRARY_OVERRIDE_&lt;LIBRARY&gt;"
             >next</a> |</li>
        <li class="right" >
          <a href="LINK_LIBRARIES_ONLY_TARGETS.html" title="LINK_LIBRARIES_ONLY_TARGETS"
             >previous</a> |</li>
  <li>
    <img src="../_static/cmake-logo-16.png" alt=""
         style="vertical-align: middle; margin-top: -2px" />
  </li>
  <li>
    <a href="https://cmake.org/">CMake</a> &#187;
  </li>
  <li>
    <a href="../index.html">3.27.4 Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-properties.7.html" >cmake-properties(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">LINK_LIBRARY_OVERRIDE</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2000-2023 Kitware, Inc. and Contributors.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 5.3.0.
    </div>
  </body>
</html>